package com.yc.fav.service.impl;

import com.yc.base.biz.BizException;
import com.yc.fav.entity.TagFav;
import com.yc.fav.mapper.TagFavMapper;
import com.yc.fav.service.ITagFavService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.session.SqlSession;
import org.example.util.MyBatisUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiaoYan
 * @since 2025-08-16
 */
@Service
public class TagFavServiceImpl extends ServiceImpl<TagFavMapper, TagFav> implements ITagFavService {

    @Override
    public void moveFav(String oldTid, String newTid, String[] fids)
            throws BizException {
        // 字段验证, 可以不验证
        SqlSession session = MyBatisUtils.getSession(false);
        try{
            TagFavMapper mapper = session.getMapper(TagFavMapper.class);
            mapper.updateFavs(oldTid, newTid, fids);
            session.commit();
        } catch (Exception e){
            session.rollback();
            throw new BizException("合并链接失败!",e);
        } finally {
            session.close();
        }
    }
}
